var $;
var from;
var colorpicker;
var dates;
layui.use(['form', 'colorpicker', 'layer'], function () {
    $ = layui.$;
    from = layui.form;
    colorpicker = layui.colorpicker;
    var layer = layui.layer;
    // //颜色选择
    colorpicker.render({
        elem: '#test-form'
        , color: '#1c97f5'
        , done: function (color) {
            $('#test-form-input').val(color);
        }
    });
    //曲线名称
    from.on("select(ident)", function (date) {
        $("#unit").empty();
        for (let i = 0; i < dates.length; i++) {
            if (date.value == dates[i].Name) {
                $("#unit").append("<option value=" + dates[i].unit + " >" + dates[i].unit + "</option>");
                $("#left").val(dates[i].min);
                $("#right").val(dates[i].max);
                $("#name2").val(dates[i].name2);
                $("#linear").val(dates[i].liner);
                $("#way").val(dates[i].show);
                $("#num").val(dates[i].num);
                $('#test-form-input').val(dates[i].Color);
                if(dates[i].box==true){
                    $("#designdatashow").prop('checked',true);
                }else{
                    $("#designdatashow").prop('checked',false);
                }
                colorpicker.render({
                    elem: "#test-form",
                    color: dates[i].Color,
                    done: function (color) {
                        $('#test-form-input').val(color);
                    }
                })
                from.render();
            }
        }

        })

       $("#num").blur(function(){
           var num=$("#num").val();
           if(num<0 || num==""){
            layer.tips("小数点值不对","#num")
            $("#num").val("2");
           }
        })
        $("#left").blur(function(){
            var left=$("#left").val();
            if(left<0 || left==""){
                $("#left").val("0")
            }
        })
        $("#right").blur(function(){
            var right=$("#right").val();
            if(right<0 || right==""){
                $("#right").val("100");
            }
        })  

        })

function child(date) {
    dates = date;
    $("#ident").empty();
    for (let i = 0; i < date.length; i++) {
        $("#ident").append("<option value=" + date[i].Name + " >" + date[i].Name + "</option>")
    }
    $("#unit").append("<option value=" + date[0].unit + " >" + date[0].unit + "</option>");
    $("#left").val(date[0].min);
    $("#right").val(date[0].max);
    $("#name2").val(date[0].name2);
    $("#linear").val(date[0].liner);
    $("#way").val(date[0].show);
    $("#num").val(date[0].num);
    if(date[0].box==true){
        $("#designdatashow").prop('checked',true);
    }else{
        $("#designdatashow").prop('checked',false);
    }
    
    $('#test-form-input').val(date[0].Color)
    colorpicker.render({
        elem: "#test-form",
        color: date[0].Color,
        done: function (color) {
            $('#test-form-input').val(color);
        }
    })
    from.render();
}

var resdate=function(){
var Name = $("#ident option:checked").text();
var name2 = $("#name2").val();
if(name2==""){
    name2=Name
}
var box=$("#designdatashow").prop("checked")
var unit = $("#unit option:checked").text();
var liner = $("#linear").val();
var show = $("#way").val();
var num = $("#num").val();
if(num==""){
   num="2"
}
var min= $("#left").val();
if(min==""){
 min="0"
}
var max= $("#right").val();
if(max==""){
 max="100"
}
var Color=$("#test-form-input").val();
var date={ Name, min, max, unit, Color, name2, num, show,box, liner }
return date;
}
